﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.ShpMana
{
    public partial class wfAddVehicle : msBsc.Cls.BPageHt
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void showVehicleType()
        {
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataTable dt = vehicleInfo.GetVehicleType();
                if (dt == null || dt.Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dt, "", "", 1, 100, "");
                this.ExecJScript(@"setSelect('vehicleType'," + retJson + ");");
            }
        }
        private void showVehicleBrand()
        {
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataTable dt = vehicleInfo.GetVehicleBrand();
                if (dt==null||dt.Rows.Count<1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dt, "", "", 1, 100, "");
                this.ExecJScript(@"setSelect('vehicleBrand'," + retJson + ");");
            }
        }
        private void showVehicleColor()
        {
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataTable dt = vehicleInfo.GetVehicleColor();
                if (dt == null || dt.Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dt, "", "", 1, 100, "");
                this.ExecJScript(@"setSelect('vehicleColor',"+retJson+");");
            }
        }

        /// <summary>
        /// 添加车辆
        /// </summary>
        ///  Author:任延华
        ///  Creation date:2014-9-1
        private void addVehicle()
        {
            //string djkId, string name, string buyTime, string seats, string price, string serviceArea, string carType, string brand, string color, string serviceType, string picture, string publisherId, string vehicleNumber
            string djkId = this.GetParamHtValue("djkId");//地接客Id
            string vehicleName = this.GetParamHtValue("vehicleName");//车辆名称
            string buyTime = this.GetParamHtValue("buyTime");//购买时间
            string seats = this.GetParamHtValue("seats");//座位数
            string price = this.GetParamHtValue("price");//价格
            string serviceArea = this.GetParamHtValue("serviceArea");//服务范围
            string vehicleType = this.GetParamHtValue("vehicleType");//车辆类型
            string vehicleBrand = this.GetParamHtValue("vehicleBrand");//车辆品牌
            string vehicleColor = this.GetParamHtValue("vehicleColor");//车辆颜色
            string serviceType = this.GetParamHtValue("serviceType");//服务类型
            string picture = this.GetParamHtValue("picture");//车辆图片
            string vehicleNumber = this.GetParamHtValue("vehicleNumber");//车牌号
            string publisherId = msBsc.SvRef.UserInfo.Operator;
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                using (msBsc.AppLogic.DataAlc.CBizSysFile oCBizSysFile = new msBsc.AppLogic.DataAlc.CBizSysFile())
                {
                    //保存到系统永久目录，之前上传时存到临时目录的，也可另写代码拷贝文件到其他目录
                    picture = oCBizSysFile.SaveImgToServer(""
                        , msBsc.SvRef.UserInfo.Operator
                        , "1"
                        , "VEH"
                        , ""
                        , picture//文件来源虚拟路径
                        , ""//文件来源物理路径，虚拟和物理只有一个就行
                        , true);
                }
                string strRet = vehicleInfo.AddVehicle(djkId, vehicleName, buyTime, seats, price, serviceArea, vehicleType, vehicleBrand, vehicleColor, serviceType, picture, publisherId, vehicleNumber);
                if (strRet != "OK")
                {
                    this.Alert(strRet);
                    return;
                }
                this.ExecJScript(@"success();");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")//初始化
            {
                showVehicleBrand();
                showVehicleType();
                showVehicleColor();
            }
            else if (this.strAction == "addVehicle")//添加车辆
            {
                addVehicle();
            }
        }
    }
}